#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int maxSubArray(vector<int>& nums) {
        int n = nums.size();
        vector<int> dp(n);
        dp[0] = nums[0];
        for (int i = 1;i < n;i++)
        {
            if (dp[i - 1] > 0)
                dp[i] = dp[i - 1] + nums[i];
            else
                dp[i] = nums[i];
        }
        int ret = -0x3f3f3f3f;
        for (int i = 0;i < n;i++)
        {
            cout << dp[i] << " ";
            ret = max(ret, dp[i]);
        }
        return ret;
    }
};